# -*- coding: utf-8 -*-
import pymysql
from datetime import date, timedelta

from dbutils.pooled_db import PooledDB

# proactive_service_data 数据源
def getDataConnection():
    # 开发环境
    #pool = PooledDB(pymysql, 1, host='172.20.151.80', user='pushdb', passwd='SkYWOrTh$TcOs',
    #                db='proactive_service_data',port=3306)  # 1为连接池里的最少连接数
    # 测试环境
    pool = PooledDB(pymysql, 1, host='172.20.154.103', user='test_dmp', passwd='DghHC3lFM1KzT3ZJ',
                    db='proactive_service_data', port=3407)  # 1为连接池里的最少连接数
    #pool = PooledDB(pymysql,1,host='127.0.0.1',user='root',passwd='root',db='life_assistant_data',port=3306) # 5为连接池里的最少连接数
    conn = pool.connection()
    cur = conn.cursor()
    return conn, cur

def subTable(serId,serName):
    before4day = (date.today() + timedelta(days=-4)).strftime("%y%m%d")
    tableName = f"log_data_{serId}_{before4day}"
    createTableDdl1 = f"""DROP TABLE IF EXISTS `{tableName}` """

    conn,cur = getDataConnection()
    cur.execute(createTableDdl1)
    conn.commit()

    print(f"------------------表{tableName} 删除成功 --------------------------")
    cur.close()
    conn.close()



if __name__ == '__main__':
    subTable('common','公共日志')
    subTable('zjkj', '早间开机')
    subTable('yjyl', '夜间音量')
    subTable('jkzx', '健康作息')
    subTable('zjtx', '追剧提醒')